package com.github.skystardust.lotteryex.lottery.item;

import com.github.skystardust.lotteryex.lottery.item.api.Require;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;

@EqualsAndHashCode(of = "uuid")
@ToString
public abstract class RequireItem<T> implements Require<T> {
    private String type;
    private UUID uuid;
    private T requireObject;

    public RequireItem(T requireObject) {
        this(UUID.randomUUID(), requireObject);
    }

    public RequireItem(UUID uuid, T requireObject) {
        this.uuid = uuid;
        this.requireObject = requireObject;
        this.type = getClass().getSimpleName();
    }

    public RequireItem(Map<String, Object> stringObjectMap) {
        this.type = getClass().getSimpleName();
        this.uuid = UUID.fromString(((String) stringObjectMap.get("uuid")));
    }

    public UUID getUuid() {
        return uuid;
    }

    public void setUuid(UUID uuid) {
        this.uuid = uuid;
    }

    public T getRequireObject() {
        return requireObject;
    }

    public void setRequireObject(T requireObject) {
        this.requireObject = requireObject;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    @Override
    public Map<String, Object> serialize() {
        TreeMap<String, Object> stringObjectTreeMap = new TreeMap<>();
        stringObjectTreeMap.put("uuid", uuid.toString());
        stringObjectTreeMap.put("requireObject", requireObject);
        return stringObjectTreeMap;
    }
}
